#pragma once

#include<iostream>
#include<unordered_map>
#include<string>
#include<fstream>
#include"Log.hpp"
using namespace LogMoudle;

const std::string step=":";

class Func{

    private:
    void Init_Dict()
    {
        std::ifstream in(_path);
        if(!in.is_open())
        {
            LOG(Logevel::INFO)<<"open file is false\n";
            exit(1);
        }
        std::string line;

        while(std::getline(in,line))
        {
            if(line.empty())continue;

            auto pos=line.find(step);
            if(pos==std::string::npos)continue;
            std::string key=line.substr(0,pos);
            std::string valus=line.substr(pos+1);
            _dict.insert(std::make_pair(key,valus));
        }
        in.close();
    }
    public:
    Func(const std::string &path):_path(path)
    {
        //对字典进行初始化
        Init_Dict();
    }
    std::string Translate(const std::string &key)
    {
        auto find_key=_dict.find(key);
        if(find_key==_dict.end())
        {
            return std::string("没有");
        }
        else{
            return find_key->second;
        }
        return "";
    }

    ~Func()
    {

    }
    private:
    std::string _path;
    std::unordered_map<std::string,std::string>_dict;
};